home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / app / HelpWindow.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  7.3 KB  |  227 lines

  1. package com.extensibility.app;
  2.  
  3. import com.extensibility.plugin.api.PrintHtml10;
  4. import com.extensibility.print.HtmlPrinter;
  5. import com.extensibility.rock.QuietBtn;
  6. import com.extensibility.rock.RAction;
  7. import com.extensibility.util.History;
  8. import com.extensibility.util.RuleSplitPane;
  9. import java.awt.BorderLayout;
  10. import java.awt.Component;
  11. import java.awt.Cursor;
  12. import java.awt.Dimension;
  13. import java.awt.Font;
  14. import java.awt.Frame;
  15. import java.awt.event.ActionEvent;
  16. import java.io.File;
  17. import java.io.FileNotFoundException;
  18. import java.io.IOException;
  19. import java.net.URL;
  20. import java.util.EventObject;
  21. import javax.swing.JEditorPane;
  22. import javax.swing.JFrame;
  23. import javax.swing.JMenuBar;
  24. import javax.swing.JScrollPane;
  25. import javax.swing.JToolBar;
  26. import javax.swing.event.HyperlinkEvent;
  27. import javax.swing.event.HyperlinkListener;
  28. import javax.swing.event.HyperlinkEvent.EventType;
  29.  
  30. public class HelpWindow extends BaseWindow implements HyperlinkListener {
  31.    JEditorPane helpText;
  32.    JScrollPane helpScroller;
  33.    JEditorPane indexText;
  34.    JScrollPane indexScroller;
  35.    RuleSplitPane split;
  36.    JToolBar toolbar;
  37.    BaseAction forwardAction;
  38.    BaseAction backAction;
  39.    BaseAction homeAction;
  40.    BaseAction printAction;
  41.    RAction copyAction;
  42.    QuietBtn forwardBtn;
  43.    QuietBtn backBtn;
  44.    URL index;
  45.    URL home;
  46.    History history;
  47.    boolean userHasBeenWarned;
  48.  
  49.    private HelpWindow() {
  50.       super(new BaseDocument());
  51.       this.history = new History();
  52.       ((JFrame)this).getContentPane().setLayout(new BorderLayout());
  53.       this.setVisible(false);
  54.       ((BaseWindow)this).setSize(640, 340);
  55.       ((Component)this).setFont(new Font("Serif", 0, 9));
  56.       this.createToolBar();
  57.       ((JFrame)this).getContentPane().add(this.toolbar, "North");
  58.       ((Frame)this).setIconImage(UI.getImage("ity.gif"));
  59.    }
  60.  
  61.    protected String getHomeShortName() {
  62.       if (this.home == null) {
  63.          return null;
  64.       } else {
  65.          String var1 = this.home.getFile();
  66.          return var1.substring(var1.lastIndexOf("/") + 1);
  67.       }
  68.    }
  69.  
  70.    public void setTitle() {
  71.       String var1 = UI.getString(this.getClassName());
  72.       ((Frame)this).setTitle(var1);
  73.    }
  74.  
  75.    public HelpWindow(String var1) {
  76.       this();
  77.       this.createContent(var1);
  78.       ((JFrame)this).getContentPane().add(this.helpScroller, "Center");
  79.       ((Frame)this).setIconImage(UI.getImage("ity.gif"));
  80.       this.homeAction.actionOccurred((ActionEvent)null);
  81.    }
  82.  
  83.    public HelpWindow(String var1, int var2, String var3) {
  84.       this();
  85.       this.createIndex(var1);
  86.       this.createContent(var3);
  87.       this.split = new RuleSplitPane(1, this.indexScroller, this.helpScroller);
  88.       this.split.setDividerRule(true, var2);
  89.       ((JFrame)this).getContentPane().add(this.split, "Center");
  90.       ((Frame)this).setIconImage(UI.getImage("ity.gif"));
  91.       this.homeAction.actionOccurred((ActionEvent)null);
  92.    }
  93.  
  94.    public void setVisible(boolean var1) {
  95.       super.setVisible(var1);
  96.       if (var1 && this.split != null) {
  97.          this.split.resetDividerLoc();
  98.       }
  99.  
  100.    }
  101.  
  102.    private JScrollPane createIndex(String var1) {
  103.       this.index = UI.getHelpURL(var1);
  104.  
  105.       try {
  106.          this.indexText = new JEditorPane(this.index);
  107.       } catch (IOException var3) {
  108.          DialogFactory.showException(this, 101, var3);
  109.          this.indexText = new JEditorPane();
  110.       }
  111.  
  112.       this.indexText.setEditable(false);
  113.       this.indexText.addHyperlinkListener(this);
  114.       this.indexText.setCursor(Cursor.getPredefinedCursor(12));
  115.       this.indexScroller = new JScrollPane(this.indexText);
  116.       this.indexScroller.setMinimumSize(new Dimension(20, 20));
  117.       this.indexText.setMinimumSize(new Dimension(300, 100));
  118.       return this.indexScroller;
  119.    }
  120.  
  121.    protected JMenuBar createMenuBar() {
  122.       return null;
  123.    }
  124.  
  125.    private JScrollPane createContent(String var1) {
  126.       this.home = UI.getHelpURL(var1);
  127.       this.setTitle();
  128.       this.helpText = new JEditorPane();
  129.       this.helpText.setEditable(false);
  130.       this.helpText.addHyperlinkListener(this);
  131.       this.helpText.setCursor(Cursor.getPredefinedCursor(12));
  132.       this.helpScroller = new JScrollPane(this.helpText);
  133.       return this.helpScroller;
  134.    }
  135.  
  136.    private JToolBar createToolBar() {
  137.       this.backAction = new BackAction(this);
  138.       this.forwardAction = new ForwardAction(this);
  139.       this.homeAction = new HomeAction(this);
  140.       this.printAction = new PrintAction(this);
  141.       this.copyAction = new CopyAction((HelpWindow)null);
  142.       this.toolbar = new BaseToolBar();
  143.       this.toolbar.setFloatable(false);
  144.       this.forwardBtn = new QuietBtn(this.forwardAction, false);
  145.       this.backBtn = new QuietBtn(this.backAction, false);
  146.       this.toolbar.add(new QuietBtn(this.homeAction, false));
  147.       this.toolbar.add(this.backBtn);
  148.       this.toolbar.add(this.forwardBtn);
  149.       this.toolbar.addSeparator();
  150.       this.toolbar.add(new QuietBtn(this.copyAction, true));
  151.       if (HtmlPrinter.canPrint()) {
  152.          this.toolbar.add(new QuietBtn(this.printAction, true));
  153.       }
  154.  
  155.       return this.toolbar;
  156.    }
  157.  
  158.    public void showPage(String var1) {
  159.       URL var2 = UI.getHelpURL(var1);
  160.       this.showPage(var2, true);
  161.    }
  162.  
  163.    protected void showPage(URL var1, boolean var2) {
  164.       if (var1 == null) {
  165.          DialogFactory.showException(this, 101, new FileNotFoundException());
  166.       } else {
  167.          try {
  168.             this.helpText.setPage(var1);
  169.             if (var2) {
  170.                this.history.add(var1);
  171.             }
  172.  
  173.             this.updateNavigationActions();
  174.          } catch (IOException var4) {
  175.             DialogFactory.showException(this, 101, var4);
  176.          }
  177.  
  178.       }
  179.    }
  180.  
  181.    private void warnUser(URL var1) {
  182.       this.userHasBeenWarned = true;
  183.       DialogFactory.caution(this, UI.getString("caution.lousy.browser", var1.toExternalForm()));
  184.    }
  185.  
  186.    public void hyperlinkUpdate(HyperlinkEvent var1) {
  187.       if (var1.getEventType() == EventType.ACTIVATED) {
  188.          this.showPage(var1.getURL(), ((EventObject)var1).getSource() == this.helpText);
  189.       } else if (var1.getEventType() == EventType.ENTERED) {
  190.          this.helpText.setCursor(Cursor.getPredefinedCursor(12));
  191.       } else if (var1.getEventType() == EventType.EXITED) {
  192.          this.helpText.setCursor(Cursor.getPredefinedCursor(2));
  193.       }
  194.  
  195.    }
  196.  
  197.    protected void updateNavigationActions() {
  198.       this.forwardBtn.setEnabled(this.history.peekNext() != null);
  199.       this.backBtn.setEnabled(this.history.peekPrev() != null);
  200.    }
  201.  
  202.    public String getClassName() {
  203.       return "com.extensibility.app.HelpWindow";
  204.    }
  205.  
  206.    public void setHome(String var1) {
  207.       this.home = UI.getHelpURL(var1);
  208.    }
  209.  
  210.    public void printWindow(ActionEvent var1) {
  211.       try {
  212.          PrintHtml10 var2 = HtmlPrinter.getPrintObject();
  213.          if (var2 != null) {
  214.             var2.setHtmlToPrint(this.helpText.getPage());
  215.             var2.doPrinting((File)null);
  216.          }
  217.       } catch (Exception var3) {
  218.          DialogFactory.showException(this, 124, var3);
  219.       }
  220.  
  221.    }
  222.  
  223.    protected String getText() {
  224.       return null;
  225.    }
  226. }
  227.